package com.example.leetcode.design;

import java.util.Arrays;
import java.util.Random;

class Solution384 {

    int[] nums;
    int[] original;

    public Solution384(int[] nums) {
        this.nums = nums;
        this.original = new int[nums.length];
        System.arraycopy(nums, 0, original, 0, nums.length);
    }

    public int[] reset() {
        System.arraycopy(original, 0, nums, 0, nums.length);
        return nums;
    }

    /**
     * 洗牌算法
     *
     * @return
     */
    public int[] shuffle() {
        Random random = new Random();
        for (int i = 0; i < nums.length; ++i) {
            int j = i + random.nextInt(nums.length - i);
            int temp = nums[i];
            nums[i] = nums[j];
            nums[j] = temp;
        }
        return nums;
    }

}

/**
 * Your Solution object will be instantiated and called as such:
 * Solution obj = new Solution(nums);
 * int[] param_1 = obj.reset();
 * int[] param_2 = obj.shuffle();
 */

public class leetcode384 {
    public static void main(String[] args) {
        int[] nums = {1, 2, 3};
        Solution384 solution384 = new Solution384(nums);
        System.out.println(Arrays.toString(solution384.shuffle()));    // 打乱数组 [1,2,3] 并返回结果。任何 [1,2,3]的排列返回的概率应该相同。例如，返回 [3, 1, 2]
        System.out.println(Arrays.toString(solution384.reset()));      // 重设数组到它的初始状态 [1, 2, 3] 。返回 [1, 2, 3]
        System.out.println(Arrays.toString(solution384.shuffle()));    // 随机返回数组 [1, 2, 3] 打乱后的结果。例如，返回 [1, 3, 2]
    }
}
